package com.example.win.android_banduyujia.peopleactivity.ui.activity;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.http.request.CheckMobileRequest;
import com.example.win.android_banduyujia.http.response.BaseHttpResponse;
import com.example.win.android_banduyujia.peopleactivity.activity.activity.ImageFetchActivity;
import com.example.win.android_banduyujia.http.request.AsycHttpRequest;

/**
 * Created by Win on 2015/8/6.
 */
public class BaseActivity extends FragmentActivity {

     public AsycHttpRequest mAsycHttpRequest = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 只支持竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        mAsycHttpRequest = new AsycHttpRequest();
    }

    public void showToast(int id){
        Toast.makeText(this, getString(id), Toast.LENGTH_SHORT).show();
    }

    public void showToast(String message){
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }

    public void showShortToast(String message){
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }

    protected void sendValidCode(String url, String cellphone){
         CheckMobileRequest request = new CheckMobileRequest(url,cellphone);
         mAsycHttpRequest.doRequest(this, request, BaseHttpResponse.class, mCallbackHandler, true);
    }

    private final Handler mCallbackHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            showToast(R.string.send_code_success);
        }
    };

    // 启动系统相机 + 截图
    public void startCameraCropActivity(int requestCode){
        Intent  intent = new Intent(this, ImageFetchActivity.class);
        intent.putExtra(ImageFetchActivity.ACTION_TYPE, ImageFetchActivity.REQUEST_CODE_CAMERA);
        startActivityForResult(intent, requestCode);
    }

    // 启动系统图册 + 截图
    public void startPictureCropActivity(int requestCode){
        Intent  intent = new Intent(this, ImageFetchActivity.class);
        intent.putExtra(ImageFetchActivity.ACTION_TYPE, ImageFetchActivity.REQUEST_CODE_ALBUM);
        startActivityForResult(intent, requestCode);
    }
}
